package fr.unice.platdujour.application;

import java.net.MalformedURLException;
import java.rmi.AlreadyBoundException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.util.Map;

import fr.unice.platdujour.chord.Tracker;
import fr.unice.platdujour.chord.TrackerImpl;

public class Network {

	private static Network instance = null;
	private Tracker tracker;
	private GuideMichelin guideMichelin;
	private Map<String, String> listeDepartMap;

	private Network(int port) throws RemoteException, MalformedURLException, AlreadyBoundException, NotBoundException {
		new TrackerImpl(port);

		this.tracker = (Tracker) Naming.lookup("rmi://localhost:" + port
				+ "/tracker");
		
		this.guideMichelin = new GuideMichelinImpl(tracker);
	}

	public synchronized static Network getInstance(int port) throws RemoteException, MalformedURLException, AlreadyBoundException, NotBoundException {
		if (instance == null) {
			instance = new Network(port);
		}

		return instance;
	}

	public Tracker getTracker() {
		return tracker;
	}

	public void setTracker(Tracker tracker) {
		this.tracker = tracker;
	}

	public GuideMichelin getGuideMichelin() {
		return guideMichelin;
	}

	public void setGuideMichelin(GuideMichelin guideMichelin) {
		this.guideMichelin = guideMichelin;
	}

	public Map<String, String> getListeDepartMap() {
		return listeDepartMap;
	}

	public void setListeDepartMap(Map<String, String> listeDepartMap) {
		this.listeDepartMap = listeDepartMap;
	}

}
